package com.microservice.salmon.core.authorization;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>
 * 资源服务器统一配置
 * </p>
 *
 * @author 王洪庆
 */
@Configuration
@EnableResourceServer
public class MicroServiceResourceServerConfig extends ResourceServerConfigurerAdapter implements WebMvcConfigurer {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .authorizeRequests()
                .mvcMatchers("/v2/api-docs")
                .permitAll().anyRequest().authenticated();
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(true)   //是否支持后缀的方式
                .ignoreAcceptHeader(false)  // 是否忽略消息头，Accept
                .favorParameter(true)		//是否支持请求参数的方式
                .parameterName("format")	//请求参数名
                .defaultContentType(MediaType.APPLICATION_ATOM_XML); //默认返回格式
    }
}
